<?php

/**
* MenuTest.php
*
* Guid add test
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/
require_once '../framework/config.php';

require_once 'simpletest/autorun.php';
require_once 'simpletest/web_tester.php';

class  MenuTest extends WebTestCase
{

    private $testGuideName,$testSlideName,$testDesc,$testGuideId,$testSlideId,$url;


    public function setUp() 
    {

        $this->testGuideName = md5(uniqid(rand(), true));
        $this->testSlideName = md5(uniqid(rand(), true));
        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
        $this->url = $global['service_url'];

        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN');  
        $dbh = new PDO($options['dsn_string']); 
        $dbh->exec("INSERT INTO guide (name) values ('".$this->testGuideName."' )");
        $this->testGuideId =  $dbh->lastInsertId();
        $dbh->exec("INSERT INTO slide ( guide_id,name,`order`) VALUES ('".$this->testGuideId."','".$this->testSlideName."',0)");
        $this->testSlideId[0] =  $dbh->lastInsertId();
        $dbh->exec("INSERT INTO slide ( guide_id,name,`order`) VALUES ('".$this->testGuideId."','".$this->testSlideName."',1)");
        $this->testSlideId[1] =  $dbh->lastInsertId();
        $dbh->exec("INSERT INTO slide ( guide_id,name,`order`) VALUES ('".$this->testGuideId."','".$this->testSlideName."',2)");
        $this->testSlideId[2] =  $dbh->lastInsertId();

        $this->addHeader("User-Agent: Mozilla/5.0 (iPhone");
    }

    public function testGuideList()
    {
        $this->get($this->url.'?cmd=GuideList');
        $this->assertText('Lista tras');
    }

    public function testGuideListShowRoute()
    {
        //>Lista tras >Pokaż trasę 
        $this->get($this->url.'?cmd=GuideList');
        $this->clickLink($this->testGuideName);
        $this->assertLink('Lista tras',$this->url.'?cmd=GuideList');
        $this->assertText('Przegląd trasy');
    }



    public function testGuideListShowRouteShowSlide()
    {
        //>Lista tras >Pokaż trasę >Edycja slajdu 
        $this->get($this->url.'?cmd=GuideList');
        $this->clickLink($this->testGuideName);
        $this->clickLink($this->testSlideName);
        $this->assertLink('Przegląd',$this->url.'?cmd=ShowRoute&id='.$this->testGuideId);
        $this->assertText('Pokaż slajd');
    }

    public function testSlideNav()
    {
        $this->get($this->url.'?cmd=ShowSlide&id='.$this->testSlideId[1].'&guide_id='.$this->testGuideId);
        $this->assertLink('poprzedni slajd',$this->url.'?cmd=ShowSlide&id='.$this->testSlideId[0].'&guide_id='.$this->testGuideId);
        $this->assertLink('następny slajd',$this->url.'?cmd=ShowSlide&id='.$this->testSlideId[2].'&guide_id='.$this->testGuideId);
        $this->clickLink('poprzedni slajd');
        $this->assertLink('następny slajd',$this->url.'?cmd=ShowSlide&id='.$this->testSlideId[1].'&guide_id='.$this->testGuideId);
        $this->clickLink('następny slajd');
        $this->clickLink('następny slajd');
        $this->assertLink('poprzedni slajd',$this->url.'?cmd=ShowSlide&id='.$this->testSlideId[1].'&guide_id='.$this->testGuideId);
    }

    public function testTwitterNav()
    {
        $this->get($this->url);
        $this->assertLink('Twitter',$this->url.'/?cmd=Twitter&refcmd=&id=&guide_id=');
        $this->clickLink('Twitter');
        $this->assertLink('Powrót',$this->url.'/?cmd=&id=&guide_id=');
        $this->clickLink('Twitter');
        $this->assertLink('Powrót',$this->url.'/?cmd=&id=&guide_id=');
       
        $this->get($this->url.'?cmd=ShowSlide&id='.$this->testSlideId[1].'&guide_id='.$this->testGuideId);

        $this->assertLink('Twitter',$this->url.'/?cmd=Twitter&refcmd=ShowSlide&id='.$this->testSlideId[1].'&guide_id='.$this->testGuideId);
        $this->clickLink('Twitter');
        $this->assertLink('Powrót',$this->url.'/?cmd=ShowSlide&id='.$this->testSlideId[1].'&guide_id='.$this->testGuideId);
        $this->clickLink('Powrót');
        $this->assertText($this->testSlideName);
 
    }



    public function tearDown() 
    {
        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN');  
  
        $dbh = new PDO($options['dsn_string']);        
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

        $dbh->exec("DELETE FROM slide WHERE guide_id=".$this->testGuideId);
        $dbh->exec("DELETE FROM guide WHERE ROWID=".$this->testGuideId);
        $dbh = null;
    }
 

}
?>
